package com.zl.smartmall.library.po;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Property;
import net.tsz.afinal.annotation.sqlite.Table;

/**
 * 活动(商城首)页最新公告
 * 
 * @author 陈希然
 * 
 */
@Table(name = "tb_ActivitiesLatestNotice")
public class ActivitiesLatestNoticeInfo extends BaseActivitiesInfo {

	@Id
	private int id;
	@Property 
	private int noticeId;
	@Property
	private int isTop;
	@Property
	private int viewCount;
	@Property
	private long time;
	@Property
	private String title;
	@Property
	private String content;
	@Property
	private String icon;
	@Property
	private String tag;
	@Property
	private String url;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getViewCount() {
		return viewCount;
	}

	public void setViewCount(int viewCount) {
		this.viewCount = viewCount;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public int getNoticeId() {
		return noticeId;
	}

	public void setNoticeId(int noticeId) {
		this.noticeId = noticeId;
	}

	public int getIsTop() {
		return isTop;
	}

	public void setIsTop(int isTop) {
		this.isTop = isTop;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	public static List<ActivitiesLatestNoticeInfo> parse(JSONArray jsonArray) throws JSONException {
//		"id": 2,
//	    "isTop": 1,
//	    "typeName": "精",
//	    "title": "五一小区游园活动，欢迎广大业主参与",
//	    "title_pic": "http://ht.meetones.com:81/mall/88d3bea306c51c3483e423d9309f41fa.jpg",
//	    "intros": "五一小区活动通知",
//	    "views": 0,
//	    "url": "http://api.meetones.com:81/community/notices?id=2",
//	    "createtime": 1429095990
		List<ActivitiesLatestNoticeInfo> activitiesLatestNoticeInfos = new ArrayList<ActivitiesLatestNoticeInfo>();
		for(int i = 0; jsonArray != null && i < jsonArray.length(); i++) {
			JSONObject jsonObject = jsonArray.getJSONObject(i);
			if(jsonObject != null && jsonObject.length() > 0) {
				ActivitiesLatestNoticeInfo activitiesLatestNoticeInfo = new ActivitiesLatestNoticeInfo();
				activitiesLatestNoticeInfo.activitiesInfoType = ActivitiesInfoType.TYPE_NOTICE;
				if(jsonObject.has("intros")) {
					activitiesLatestNoticeInfo.content = jsonObject.getString("intros");
				}
				if(jsonObject.has("title_pic")) {
					activitiesLatestNoticeInfo.icon = jsonObject.getString("title_pic");
				}
				activitiesLatestNoticeInfo.noticeId = jsonObject.getInt("id");
				activitiesLatestNoticeInfo.tag = jsonObject.getString("typeName");
				activitiesLatestNoticeInfo.title = jsonObject.getString("title");
				activitiesLatestNoticeInfo.url = jsonObject.getString("url");
				activitiesLatestNoticeInfo.viewCount = jsonObject.getInt("views");
				activitiesLatestNoticeInfo.time = jsonObject.getLong("createtime");
				activitiesLatestNoticeInfo.isTop = jsonObject.getInt("isTop");
				activitiesLatestNoticeInfos.add(activitiesLatestNoticeInfo);
			}
			
		}
		
		return activitiesLatestNoticeInfos;
	}
}
